﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace FunMazeClient
{
    class ConnectToGame
    {
        //private IMediator im = null;
        //private EventsClass em = null;
        //private ArrayList clientList = null;

        //private IClientImplement iciClient = null;
        private Hashtable hsPrivateWindows = new Hashtable();
        //private string tcpServerUrl = ConfigurationSettings.AppSettings["TcpServerURL"].ToString();

        //private bool StartTcpServer()
        //{
        //    bool result = false;
        //    try
        //    {
        //        BinaryClientFormatterSinkProvider bcfs = new BinaryClientFormatterSinkProvider();
        //        BinaryServerFormatterSinkProvider bsfs = new BinaryServerFormatterSinkProvider();
        //        bsfs.TypeFilterLevel = TypeFilterLevel.Full;

        //        IDictionary id = new Hashtable();
        //        id = new Hashtable();
        //        id["port"] = 0;
        //        id["typeFilterLevel"] = TypeFilterLevel.Full;
        //        id["name"] = System.Guid.NewGuid().ToString();

        //        TcpChannel tcc = new TcpChannel(id, bcfs, bsfs);
        //        ChannelServices.RegisterChannel(tcc);
        //        this.im = (IMediator)Activator.GetObject(typeof(IMediator), this.tcpServerUrl);
        //        result = true;

        //    }
        //    catch (RemotingException ex)
        //    {
        //        MessageBox.Show(ex.Message + " Stact trace: " + ex.StackTrace);
        //    }
        //    finally
        //    {
        //    }
        //    return result;
        //}

        //private void btnConnect_Click(object sender, EventArgs e)
        //{
           
        //        StartTcpServer();

        //        if (this.im != null)
        //        {
        //            this.em = new EventsClass();
        //            this.em.PlayerName = this.txtUserName.Text;
        //            this.em.Message = "Hi!! I'm joining chat..";

        //            this.em.playerListHandler += new GetPlayerList(this.em_ClientListHandler);
        //            this.em.WelComeHandler += new WelComeMessage(this.em_WelComeHandler);
        //            this.em.GetMessageFromOthersHandler += new GetMessageFromOthers(this.em_GetMessageFromOthersHandler);
        //            this.em.UserLeftHandler += new UserLeftChat(this.em_UserLeftHandler);
        //            try
        //            {
        //                this.im.ConnectToChat(em);
        //                this.btnConnect.Enabled = false;
        //                //this.stsConnected.Text = em.UserName + " successfully connected.";
        //                this.Text = em.UserName;
        //                this.grpSend.Enabled = true;
        //                this.txtUserName.Enabled = false;
        //                this.txtMessage.BackColor = Color.LightCyan;
        //                this.txtSendMessage.BackColor = Color.LightYellow;
        //            }
        //            catch (RemotingException ex)
        //            {
        //                this.lblErrorMessage.Text = ex.Message;
        //                MessageBox.Show("Exception occured. " + ex.Message);
        //                this.ReleaseHandlers();
        //            }
        //            catch (System.Net.Sockets.SocketException socEx)
        //            {
        //                this.lblErrorMessage.Text = socEx.Message;
        //                MessageBox.Show("Exception occured. " + socEx.Message);
        //                this.ReleaseHandlers();
        //            }
        //            catch (Exception ex)
        //            {
        //                this.lblErrorMessage.Text = ex.Message;
        //                MessageBox.Show("Exception occured. " + ex.Message);
        //                this.ReleaseHandlers();
        //            }
        //        }
        //    }
    }
    
}
